package constant

/* transaction mode  start */
type TxnMode int

const (
	_ TxnMode = iota
	SOA
	EDA
)

const (
	DXC_CONTEXT_KEY = "dxc_context_key"
)

/* dxc server */
const (
	TXN_BEGIN_TOPIC_ID   = "TXN_BEGIN"
	TXN_JOIN_TOPIC_ID    = "TXN_JOIN"
	TXN_END_TOPIC_ID     = "TXN_END"
	TXN_CALLBACK_NODE_ID = "NODE0001"
)

const (
	ENV_NODE_ID_KEY     = "NODE_ID"
	ENV_INSTANCE_ID_KEY = "INSTANCE_ID"
)

const (
	CANNOT_FOUND_ROOT_XID_ERROR_CODE = -99
	DEFAULT_MAX_CALLBACK_CHANNEL     = 1024
)

const (
	APM_ATTACH                         = "_apm_attach"
	APM_ATTACH_CALLBACK_CONFIRM        = "cb:c1"
	APM_ATTACH_CALLBACK_CANCEL         = "cb:c2"
	APM_ATTACH_PARTICIPATOR_NUM_PREFIX = "pn:"
)

const (
	// redis data structure:
	// use hash,redis key: `nodeId`:`rootXid`
	// hash key: regTm                              	   hash value: RootTxn Register Timestamp
	// hash key: txSts                                     hash value: RootTxn Status (0-trying, 1-confirming, 2-confirmed, 3-cancelling, 4-cancelled)
	// hash key: stRcTm                      	   		   hash value: RootTxn Start Recovery Timestamp (only recovery use)
	// hash key: hasExpTm                         	  	   hash value: RootTxn HasExpireTime
	// hash key: @`branchXid`                              hash value: branch info (json, TsInfo struct)
	// hash key: `branchXid`_sts                           hash value: branch status (0-trying, 1-confirmed, 2-cancelled)
	// hash key: `branchXid`_rcTms                  	   hash value: branch recoverTimes
	// hash key: `branchXid`_lstUpTm                	   hash value: branch LastUpdateTime (only recover use)
	// hash key: `branchXid`_igCancel 				   	   hash value: branch TryFailedIgnoreCallbackCancel
	CACHE_REGISTER_TIME_KEY           = "regTm"
	CACHE_TX_STATUS_KEY               = "txSts"
	CACHE_START_RECOVER_TIME_KEY      = "stRcTm"
	CACHE_HAS_EXPIRE_TIME_KEY         = "hasExpTm"
	CACHE_BRANCH_KEY_PREFIX           = "@"
	LENGTH_OF_CACHE_BRANCH_KEY_PREFIX = len(CACHE_BRANCH_KEY_PREFIX)

	CACHE_BRANCH_STATUS_SUFFIX_KEY                            = "_sts"
	CACHE_BRANCH_RECOVER_TIMES_SUFFIX_KEY                     = "_rcTms"
	CACHE_BRANCH_LAST_UPDATE_TIME_SUFFIX_KEY                  = "_lstUpTm"
	CACHE_BRANCH_TRY_FAILED_IGNORE_CALLBACK_CANCEL_SUFFIX_KEY = "_igCancel"

	REDUNDANCY_ABNORMAL_TRANSACTION_METHOD_FIELDS_JSON_SPLIT = "@"
)

const (
	// root transaction status: 0-trying, 1-confirming, 2-confirmed, 3-cancelling, 4-cancelled
	ROOT_TXN_STATUS_TRYING     = "0"
	ROOT_TXN_STATUS_CONFIRMING = "1"
	ROOT_TXN_STATUS_CONFIRMED  = "2"
	ROOT_TXN_STATUS_CANCELLING = "3"
	ROOT_TXN_STATUS_CANCELLED  = "4"

	// branch transaction status: 0:trying, 1-confirmed, 2-cancelled
	BRANCH_TXN_STATUS_TRYING    = "0"
	BRANCH_TXN_STATUS_CONFIRMED = "1"
	BRANCH_TXN_STATUS_CANCELLED = "2"
)
